package com.weipai.springboot.module.controller;

import com.weipai.springboot.model.api.Response;
import com.weipai.springboot.module.service.InventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 曹朋飞
 * @Date: 2018/08/22 17:55
 * <p>
 * 库存控制类
 */
@RestController
public class InventoryController {

    @Autowired
    InventoryService inventoryService;

    /**
     * 分页查询货品
     *
     * @param page    页码
     * @param size    每页条数
     * @param isAudit ，默认为  0表示未审核,1表示审核通过，-1表示拒绝',
     * @param search  无搜索传入paging
     */
    //@GetMapping("/inventory/productList/{page}/{size}/{draw}/{productCategoryId}/{isAudit}")
    @GetMapping("/inventory/productList")
    public Response productList(@RequestParam(value = "page") Integer page,
                                @RequestParam(value = "size") Integer size,
                                @RequestParam(value = "draw") String draw,
                                @RequestParam(value = "productCategoryId", required = false) String productCategoryId,
                                @RequestParam(value = "isAudit") Integer isAudit,
                                @RequestParam("search") String search) {
        return inventoryService.selectAllProductByPage(page, size, draw, productCategoryId, isAudit,
                search);
    }

    /**
     * 前台搜索重写
     */
//    @GetMapping("/inventory/searchGoodsByKeyWord")
//    public Response productList(@RequestParam(value = "page") Integer page,
//                                @RequestParam(value = "size") Integer size,
//                                @RequestParam(value = "draw") String draw,
//                                @RequestParam(value = "productCategoryId", required = false) String productCategoryId,
////                                @RequestParam(value = "isAudit") Integer isAudit,
//                                @RequestParam("query") String query,
//                                @RequestParam("sort") String sort,
//                                @RequestParam("way") String way,
//                                @RequestParam("isNews") String sort,
//                                @RequestParam("sNews") String sort,
//
//    ) {
//
//
//        return inventoryService.selectAllProductBySearch(page, size, draw, productCategoryId, isAudit, search);
//    }

    /**
     * 分页查询单一货品的所有商品
     *
     * @param page 页码
     * @param size 每页条数
     */
    @GetMapping("/inventory/goodsListByProductId/{page}/{size}/{draw}/{spuNumber}")
    public Response goodsListByProductId(@PathVariable("page") Integer page,
                                         @PathVariable("size") Integer size,
                                         @PathVariable("draw") String draw,
                                         @PathVariable("spuNumber") String spuNumber) {
        return inventoryService.selectAllGoodsByProductId(page, size, draw, spuNumber);
    }


}
